<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<% String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>新增集团成员</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<script type="text/javascript">
var groupId = '${groupId}';
var flag = false ;
$(function(){
	
	var _url = '<%=path%>/splGroup/toSplGroupMemberListPage.do?splTypCd=23&isAddMember=1'
		$("#ligergrid1").ligerGrid({
			url: _url,
	    	method : 'get',
			columns: [ 
			           	{ display: '公司名称', name: 'splName', align:'left', width: 250 },
			            { display: '公司地址', name: 'addrRelInfo', align:'left', width: 250},
			            { display: '所属集团', name: 'splGroupNm',align:'left',width: 250},
			          ],
			        pageSize:10,
			        root:'rows',
			        record:'total',
			        hideLoadButton : true,
			        width: '100%',
			        height:'100%',
			        heightDiff:-2,
			        checkbox:true,
			        fixedCellHeight: false,
			        rownumbers:true
		});
		grid = liger.get("ligergrid1");
	    grid.setHeight(100);
	    $("#searchBar").ligerForm();
	    $("#searchBtn").click(function(event) {
	         var form = new liger.get("searchBar");
	         var data = form.getData();
	         console.log(JSON.stringify(data));
	         for (name in data){
	            grid.setParm(name,data[name]);
	         };
	        grid.reload();
	    });
	    
	    
	    $("#addBtn").click(function(){
	     	var selectedRows = grid.getSelectedRows();
	    	if (selectedRows.length != 1) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                return false;
            } 
	    	//是否同时添加集团下所有成员
	    	var _isAddAll = 0 ;
	    	var isDefault = $("#isDefault");
	    	if(isDefault.prop('checked')){
	    		_isAddAll = 1 ;
	    	}
	    	console.log("id:"+selectedRows[0].id);
	    	$.ajax({
	              type: 'post',
	              dataType: 'json',
	              data: {memberId: selectedRows[0].id,oldGroupId:selectedRows[0].splGroupId,groupId:groupId,isAddAll:_isAddAll,},
	              url: '<%=path%>/splGroup/add.do',
	              beforeSend: function () {
	                  wait_dialog = $.ligerDialog.SQalert({
	                      content: LogUtils.LOG_CMM_DATA_LOADING,
	                      SQ_type: "waitting"
	                  });
	              },
	              success: function (msg) {
	                  wait_dialog.close();
	                  if (msg.success == 1) {
	                      $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
	                      parent.callback();
	                      frameElement.dialog.close();
	                  } else {
	                      $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
	                  }
	              }
	          });
	    })
})

</script>
<body class="iframeBody">
<div class="Wrapper">
	<div class="searchArea">
	    <form id="searchBar">
	    	<div class="fieldset1 clearFix">
	            <div class="fieldBox">
	                <div class="label">公司名称</div>
	                <div class="field">
	                    <input name="splNm" id="splNm" type="text" class="ui-textbox" value="">
	                </div>
	            </div>
	         <div class="clearFix"></div>
			<div class="btnsBox formBtns notRight">
                <span id="searchBtn" class="sq-button-round">搜索</span>
            </div>     
            </div>
	    </form>
	</div>
	<div class="sqPanel_body">
		<div id="ligergrid1" class="sq-grid"></div>
	</div>
	<div  align="center">
		<div class="btnsBox">
			<span id="addBtn" class="sq-button sq-button-round">添加为集团成员</span>
		</div>
		<div>
			<input class = "ui-radio" id = "isDefault" type="checkbox" value = "1" checked="checked">同时添加该成员所在集团的其他成员！
		</div>
	</div>
</div>
</body>
</html>